package com.wh.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wh.system.dao.EmployeeRoleDao;
import com.wh.system.dto.EmployeeRoleDto;
import com.wh.system.pojo.EmployeeRole;
import com.wh.system.service.IEmployeeRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeRoleServiceimpl implements IEmployeeRoleService {
    @Autowired
    private EmployeeRoleDao employeeRoleDao;
    @Override
    public void add(EmployeeRole employeeRole) {
        employeeRoleDao.insert(employeeRole);
    }

    @Override
    public void del(Long id) {
        employeeRoleDao.deleteById(id);
    }

    @Override
    public void upd(EmployeeRole employeeRole) {
        employeeRoleDao.updateById(employeeRole);
    }

    @Override
    public List<EmployeeRole> findAll() {
        return employeeRoleDao.selectList(null);
    }

    @Override
    public EmployeeRole findById(Long id) {
        return employeeRoleDao.selectById(id);
    }

    @Override
    public IPage<EmployeeRole>findByPage(EmployeeRoleDto employeeRoleDto){
        //1.创建查询条件
        QueryWrapper<EmployeeRole> qw = new QueryWrapper<>();
        //qw.like("xxx",employeeRoleDto.getXxx());
        //qw.or();
        //qw.like("xxx",employeeRoleDto.getXxx());
        //2.组件分页数据
        IPage<EmployeeRole> page = new Page<>(employeeRoleDto.getCurrentPage(), employeeRoleDto.getPageSize());
        page.setRecords(employeeRoleDao.findByPage(page,qw));
        page.setTotal(employeeRoleDao.selectCount(qw));
        //3.返回
        return page;
    }
    @Override
    public void patchDel(List<Long> ids) {
        employeeRoleDao.deleteBatchIds(ids);
    }
}
